﻿using System.Collections.Generic;
using System.Xml;
using UnityEngine;

public class ReadMenuInfo : MonoBehaviour {

    private readonly XmlDocument xmlDoc = new XmlDocument();
    private const string XmlFileName = "MenuInfo.xml";
    private const string MenuInfo = "MenuInfo";
    private const string ItemName = "ItemName";
    private const string BpType = "BPType";
    private const string TagId = "TagId";

    public List<string> MenuMessage = new List<string>();

    private void ReadMenuMsg()
    {
        string filePath = Application.streamingAssetsPath + "/" + XmlFileName;
        this.xmlDoc.Load(filePath);
        XmlNodeList xmlNodeList = xmlDoc.SelectSingleNode(MenuInfo).ChildNodes;
        foreach (XmlElement xmlElement in xmlNodeList)
        {
            XmlNodeList menuNodeList = xmlElement.SelectNodes(ItemName);
            string msgItem = "";
            foreach (XmlElement xmlElement1 in menuNodeList)
            {
                //Debug.Log(xmlElement1.InnerText);
                msgItem += (xmlElement1.InnerText + "/");
            }
            XmlNode menuNodeType = xmlElement.SelectSingleNode(BpType);
            if (menuNodeType.InnerText != "")
                msgItem += menuNodeType.InnerText;
            else
            {
                XmlNode menuNodeId = xmlElement.SelectSingleNode(TagId);
                msgItem += menuNodeId.InnerText;
            }

            this.MenuMessage.Add(msgItem);
            //Debug.Log(msgItem);
        }
    }

    private void Awake()
    {
        this.ReadMenuMsg();
    }
}
